package com.smart.community.feign.device.fallback;

import com.smart.community.feign.device.IDeviceStatisticsFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 设备统计Feign降级处理工厂
 * 
 * @author Wu.Liang
 * @version 1.0.0
 * @since 2025-01-30
 */
@Slf4j
@Component
public class DeviceStatisticsFeignFallbackFactory implements FallbackFactory<IDeviceStatisticsFeign> {

    @Override
    public IDeviceStatisticsFeign create(Throwable cause) {
        log.warn("设备服务调用失败，执行降级处理: {}", cause.getMessage(), cause);
        
        return new IDeviceStatisticsFeign() {
            @Override
            public Double getDeviceOnlineRateByCommunityIds(List<Long> communityIds) {
                log.warn("根据社区ID列表获取设备在线率失败，communityIds: {}", communityIds);
                return 0.0;
            }
            
            @Override
            public Double getDeviceOnlineRateByPropertyCompanyIds(List<Long> propertyCompanyIds) {
                log.warn("根据物业公司ID列表获取设备在线率失败，propertyCompanyIds: {}", propertyCompanyIds);
                return 0.0;
            }
        };
    }
}
